﻿//
//  Bow.h
//  Archer
//
//  Created by Wu Wang on 12-4-23.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#ifndef Archer_Bow_h
#define Archer_Bow_h
#include "cocos2d.h"

const float BOW_BACK_SPEED = 10.0f;
class CSpriteBow : public cocos2d::CCSprite
{
public:
	CSpriteBow() 
    : m_ptUp(ccp(50, 50))
    , m_ptDown(ccp(50, 100))
    , m_ptCenter(ccp(50, 75))
	{
        
	}
    
    virtual void draw();
    
	static CSpriteBow *spriteWithFile(const char *fileName);
    static CSpriteBow *spriteWithSpriteFrameName(const char *fileName);
    
    void TestBack();
	void SetLinePara(cocos2d::CCPoint ptUp, cocos2d::CCPoint ptDown);
    // 当处于被点击状态时，则不会TestBack
	void SetIsTouched(bool bTouched)          {m_bTouched = bTouched;}
    void SetCenter(cocos2d::CCPoint ptCenter) {m_ptCenter = ptCenter;}
    void SetSpace(float space)                {m_space = space;}
    void SetMaxPower(float power)             {m_maxPower = power;}

	void SetLength(float length)
	{
		m_ptCenter = ccp((m_ptUp.x + m_ptDown.x)*0.5f - length, (m_ptUp.y + m_ptDown.y)*0.5f);
	}
    
	    
	cocos2d::CCPoint GetWorldCenterPos()
	{
		return convertToWorldSpace(m_ptCenter);
	}
    
	cocos2d::CCPoint GetWorldCenterOrgPos()
	{
		return convertToWorldSpace(ccp((m_ptUp.x + m_ptDown.x)*0.5f, (m_ptUp.y + m_ptDown.y)*0.5f));
	}
    
    cocos2d::CCPoint GetWorldUpPos()
    {
        return convertToWorldSpace(m_ptUp);
    }
    
    cocos2d::CCPoint GetWorldDownPos()
    {
        return convertToWorldSpace(m_ptDown);
    }
    
	cocos2d::CCPoint GetLocalCenterPos()
	{
		return m_ptCenter;
	}
    
	cocos2d::CCPoint GetLocalCenterOrgPos()
	{
		return ccp((m_ptUp.x + m_ptDown.x)*0.5f, (m_ptUp.y + m_ptDown.y)*0.5f);
	}
    
        
    float GetSpace()    {return m_space;}
    float GetMaxPower() {return m_maxPower;}
private:
	cocos2d::CCPoint m_ptUp;
	cocos2d::CCPoint m_ptDown;
	cocos2d::CCPoint m_ptCenter;
	bool             m_bTouched;
	float            m_length;
    
    float            m_space;
    float            m_maxPower;
    
};

// 弓箭初始化信息
struct BowInfo
{
    cocos2d::CCPoint _ptSize;
    cocos2d::CCPoint _ptAnchor;
    cocos2d::CCPoint _ptRight;      // 弓弦右侧绑定位置
    cocos2d::CCPoint _ptLeft;       // 弓弦左键绑定位置
    float            _space;        // 弓箭把手处与弓弦中点处距离
    char             _name[32];
};

class CBowManager
{
public:
    static const BowInfo &GetBowInfo(int id); 
};

#endif
